package simpleGeom;


public class PlaneSimple {
float nx;
float ny;
float nz;
float d0=0;//distanceToOrigin;
//hessian normal form
public PlaneSimple( float px,float py,float pz,float nx,float ny,float nz){
	// p=origin, n=normal
	//normal should be normalized;
	this.nx=nx;
	this.ny=ny;
	this.nz=nz;
	d0=-dot(px,py,pz,nx,ny,nz);
}

public float dot(float x1,float y1,float z1,float x2,float y2,float z2){
	return  x1 *x2 + y1 * y2 + z1 *z2;
}

public float getDistanceSigned(float x, float y, float z){
	return dot(nx,ny,nz,x,y,z)+d0;
}

public float[] intersectWithLine(float ax,float ay,float az,float bx,float by,float bz){
	float d0=getDistanceSigned(ax,ay,az);
	float d1=getDistanceSigned(bx,by,bz);
	float f=d0/(d0-d1);
	float vx=(bx-ax)*f+ax;
	float vy=(by-ay)*f+ay;
	float vz=(bz-az)*f+az;
	return new float[]{vx,vy,vz};
}
}

